package cn.com.kh;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.UUID;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import cn.com.elite.EliteBean;
import org.springframework.jdbc.core.JdbcTemplate;

/**
 * @Title: LogToDB
 * @Description: 将接口交互内容记录到数据库
 * @author: LiJuntao
 * @date 2019-12-13 上午10:05:30
 */

public class LogToDB {
    private static final Log log = LogFactory.getLog(LogToDB.class);

    public static void toDB(final EliteBean eliteBean, final String dataSource, final String Name, final String Type, final String Request, final String Response, final String Consume, final String Remark) {
        try {
            String Log_Guid = UUID.randomUUID().toString();
            Date date = new Date();
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            final String nowTime = simpleDateFormat.format(date);

            String updateSQL = "Insert Into Ws_Interface_Log (Log_Guid, Name, Time, Type, Request, Response, Consume, Remark) Values ('" + Log_Guid + "','" + Name + "', '" + nowTime + "', '" + Type + "', '" + Request + "', '" + Response + "', '" + Consume + "', '" + Remark + "')";
            eliteBean.update(updateSQL, dataSource);

        } catch (Exception e) {
            log.error("LogToDB Exception:", e);
        }
    }

    /**
     * @param eliteBean: 数据源Bean
     * @param p_Oper_No: 操作序号
     * @param Title: 操作名称
     * @param Op_Type: 操作类型
     * @param Op_Comment: 操作备注
     * @param Oper_Type: 操作任务类型 -1删除 0更新 1新增
     * @param Oper_Target: 操作对象
     * @param Old_Param: 对象原信息
     * @param New_Param: 对象新信息
     * @param Rolegroup_Id: 操作组ID
     * @param Staff_Id: 操作人ID
     * @param Status: 操作状态0正常 其他不正常
     * @return void
     * @author LiJT
     * @description TODO
     * @date 2022-12-19 15:31
     */
    public static void toSys_Oper_Log(EliteBean eliteBean, String p_Oper_No, String Title, String Op_Type, String Op_Comment, String Oper_Type, String Oper_Target, String Old_Param, String New_Param, String Rolegroup_Id, String Staff_Id, String Status) {
        try {
            JdbcTemplate jt = new JdbcTemplate(eliteBean.getDataSource());
            String Log_Guid = UUID.randomUUID().toString();
            Date date = new Date();
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            String Oper_Time = simpleDateFormat.format(date);

            String updateSQL = "Insert Into Sys_Oper_Log (Oper_Id, Oper_No, Title, Op_Type, Op_Comment, Oper_Type, Oper_Target, Old_Param, New_Param, Rolegroup_Id, Staff_Id, Status, Oper_Time) Values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";

            jt.update(updateSQL, Log_Guid, p_Oper_No, Title, Op_Type, Op_Comment, Oper_Type, Oper_Target, Old_Param, New_Param, Rolegroup_Id, Staff_Id, Status, Oper_Time);

        } catch (Exception e) {
            log.error("LogToDB Exception:", e);
        }
    }

}